﻿namespace jzgl.Windows
{
    using jzgl.Controller;
    using jzgl.Model;
    using System;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Windows.Forms;

    public class DesStyleInfo : Form
    {
        private Button btn_Add_Edit;
        private Button btn_Cancel;
        private Button btn_ShanChu;
        private Button btn_TianJia;
        private Button btn_XiuGai;
        private DataGridViewTextBoxColumn Column1;
        private DataGridViewTextBoxColumn Column2;
        private IContainer components = null;
        private DataGridView dataGridView1;
        private GroupBox groupBox1;
        private GroupBox groupBox2;
        private GroupBox groupBox3;
        private Label label1;
        private Panel panel1;
        private DesStyle style = new DesStyle();
        private DesStyleDB styleDB = new DesStyleDB();
        private int t = 0;
        private DataTable table = null;
        private TextBox textBox1;

        public DesStyleInfo()
        {
            this.InitializeComponent();
            this.groupBox2.Visible = true;
            this.groupBox3.Visible = false;
            this.Data_bind();
        }

        private void btn_Add_Edit_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.textBox1.Text.Trim().Equals(""))
                {
                    MessageBox.Show("风格名称不能为空！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                else
                {
                    this.style._DesStyleName = this.textBox1.Text.Trim();
                    if ((this.t == 1) && (this.styleDB.Add_DesStyle(this.style) != 0))
                    {
                        MessageBox.Show("添加完成！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        this.t = 0;
                    }
                    if (this.t == 2)
                    {
                        this.style._DesStyleId = int.Parse(this.dataGridView1.CurrentRow.Cells[0].Value.ToString().Trim());
                        if (this.styleDB.Update_DesStyle(this.style) != 0)
                        {
                            MessageBox.Show("成功修改！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                            this.t = 0;
                        }
                    }
                    this.Data_bind();
                    this.groupBox2.Visible = true;
                    this.groupBox3.Visible = false;
                    this.dataGridView1.Enabled = true;
                    this.textBox1.Text = "";
                }
            }
            catch (Exception)
            {
            }
        }

        private void btn_Cancel_Click(object sender, EventArgs e)
        {
            try
            {
                this.groupBox2.Visible = true;
                this.groupBox3.Visible = false;
                this.textBox1.Text = "";
                this.dataGridView1.Enabled = true;
            }
            catch (Exception)
            {
            }
        }

        private void btn_ShanChu_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.dataGridView1.CurrentRow.Cells[0].Value.ToString().Trim().Equals("") || (this.dataGridView1.Rows.Count == 0))
                {
                    MessageBox.Show("没有数据可删除！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                else if (this.dataGridView1.CurrentRow.Cells[0].Value.ToString().Trim().Equals(""))
                {
                    MessageBox.Show("请选择要删除的数据行！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                else if (MessageBox.Show("确定要删除吗？", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    this.style._DesStyleId = int.Parse(this.dataGridView1.CurrentRow.Cells[0].Value.ToString().Trim());
                    if (this.styleDB.Delete_DesStyle(this.style) != 0)
                    {
                        MessageBox.Show("已删除！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        this.Data_bind();
                    }
                }
            }
            catch (Exception)
            {
            }
        }

        private void btn_ShuaXin_Click(object sender, EventArgs e)
        {
            try
            {
                this.textBox1.Text = "";
                this.dataGridView1.Enabled = true;
                this.Data_bind();
            }
            catch (Exception)
            {
            }
        }

        private void btn_TianJia_Click(object sender, EventArgs e)
        {
            try
            {
                this.t = 1;
                this.dataGridView1.Enabled = false;
                this.groupBox3.Visible = true;
                this.groupBox2.Visible = false;
            }
            catch (Exception)
            {
            }
        }

        private void btn_XiuGai_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.dataGridView1.CurrentRow.Cells[0].Value.ToString().Trim().Equals("") || (this.dataGridView1.Rows.Count == 0))
                {
                    MessageBox.Show("没有数据可修改！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                else
                {
                    this.t = 2;
                    this.groupBox3.Visible = true;
                    this.groupBox2.Visible = false;
                    this.textBox1.Text = this.dataGridView1.CurrentRow.Cells[1].Value.ToString();
                }
            }
            catch (Exception)
            {
            }
        }

        public void Data_bind()
        {
            try
            {
                this.dataGridView1.Rows.Clear();
                this.table = this.styleDB.Show_DesStyle();
                if (this.table != null)
                {
                    for (int i = 0; i < this.table.Rows.Count; i++)
                    {
                        object[] values = new object[] { this.table.Rows[i][0].ToString(), this.table.Rows[i][1].ToString() };
                        this.dataGridView1.Rows.Add(values);
                    }
                }
                this.textBox1.Text = "";
            }
            catch (Exception)
            {
            }
        }

        private void dataGridView1_CellClick_1(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                this.textBox1.Text = this.dataGridView1.CurrentRow.Cells[1].Value.ToString();
            }
            catch (Exception)
            {
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            this.panel1 = new Panel();
            this.groupBox3 = new GroupBox();
            this.btn_Cancel = new Button();
            this.btn_Add_Edit = new Button();
            this.textBox1 = new TextBox();
            this.label1 = new Label();
            this.groupBox2 = new GroupBox();
            this.btn_ShanChu = new Button();
            this.btn_XiuGai = new Button();
            this.btn_TianJia = new Button();
            this.groupBox1 = new GroupBox();
            this.dataGridView1 = new DataGridView();
            this.Column1 = new DataGridViewTextBoxColumn();
            this.Column2 = new DataGridViewTextBoxColumn();
            this.panel1.SuspendLayout();
            this.groupBox3.SuspendLayout();
            this.groupBox2.SuspendLayout();
            this.groupBox1.SuspendLayout();
            ((ISupportInitialize) this.dataGridView1).BeginInit();
            base.SuspendLayout();
            this.panel1.Controls.Add(this.groupBox3);
            this.panel1.Controls.Add(this.groupBox2);
            this.panel1.Controls.Add(this.groupBox1);
            this.panel1.Location = new Point(-1, 2);
            this.panel1.Name = "panel1";
            this.panel1.Size = new Size(0x1ca, 0x1d1);
            this.panel1.TabIndex = 0;
            this.groupBox3.Controls.Add(this.btn_Cancel);
            this.groupBox3.Controls.Add(this.btn_Add_Edit);
            this.groupBox3.Controls.Add(this.textBox1);
            this.groupBox3.Controls.Add(this.label1);
            this.groupBox3.Location = new Point(3, 0x189);
            this.groupBox3.Name = "groupBox3";
            this.groupBox3.Size = new Size(0x1c3, 0x45);
            this.groupBox3.TabIndex = 2;
            this.groupBox3.TabStop = false;
            this.btn_Cancel.Location = new Point(0x173, 0x1a);
            this.btn_Cancel.Name = "btn_Cancel";
            this.btn_Cancel.Size = new Size(0x47, 0x17);
            this.btn_Cancel.TabIndex = 3;
            this.btn_Cancel.Text = "取消(&C)";
            this.btn_Cancel.UseVisualStyleBackColor = true;
            this.btn_Cancel.Click += new EventHandler(this.btn_Cancel_Click);
            this.btn_Add_Edit.Location = new Point(0x126, 0x1a);
            this.btn_Add_Edit.Name = "btn_Add_Edit";
            this.btn_Add_Edit.Size = new Size(0x47, 0x17);
            this.btn_Add_Edit.TabIndex = 2;
            this.btn_Add_Edit.Text = "确定(&O)";
            this.btn_Add_Edit.UseVisualStyleBackColor = true;
            this.btn_Add_Edit.Click += new EventHandler(this.btn_Add_Edit_Click);
            this.textBox1.Location = new Point(0x47, 0x1a);
            this.textBox1.Name = "textBox1";
            this.textBox1.Size = new Size(0xd3, 0x15);
            this.textBox1.TabIndex = 1;
            this.label1.AutoSize = true;
            this.label1.Location = new Point(8, 30);
            this.label1.Name = "label1";
            this.label1.Size = new Size(0x41, 12);
            this.label1.TabIndex = 0;
            this.label1.Text = "风格名称：";
            this.groupBox2.Controls.Add(this.btn_ShanChu);
            this.groupBox2.Controls.Add(this.btn_XiuGai);
            this.groupBox2.Controls.Add(this.btn_TianJia);
            this.groupBox2.Location = new Point(5, 0x189);
            this.groupBox2.Name = "groupBox2";
            this.groupBox2.Size = new Size(0x1c1, 0x45);
            this.groupBox2.TabIndex = 1;
            this.groupBox2.TabStop = false;
            this.btn_ShanChu.Location = new Point(0x11e, 20);
            this.btn_ShanChu.Name = "btn_ShanChu";
            this.btn_ShanChu.Size = new Size(0x4d, 0x17);
            this.btn_ShanChu.TabIndex = 2;
            this.btn_ShanChu.Text = "删除(&D)";
            this.btn_ShanChu.UseVisualStyleBackColor = true;
            this.btn_ShanChu.Click += new EventHandler(this.btn_ShanChu_Click);
            this.btn_XiuGai.Location = new Point(0xcc, 20);
            this.btn_XiuGai.Name = "btn_XiuGai";
            this.btn_XiuGai.Size = new Size(0x4c, 0x17);
            this.btn_XiuGai.TabIndex = 1;
            this.btn_XiuGai.Text = "修改(&E)";
            this.btn_XiuGai.UseVisualStyleBackColor = true;
            this.btn_XiuGai.Click += new EventHandler(this.btn_XiuGai_Click);
            this.btn_TianJia.Location = new Point(0x7c, 20);
            this.btn_TianJia.Name = "btn_TianJia";
            this.btn_TianJia.Size = new Size(0x4a, 0x17);
            this.btn_TianJia.TabIndex = 0;
            this.btn_TianJia.Text = "添加(&A)";
            this.btn_TianJia.UseVisualStyleBackColor = true;
            this.btn_TianJia.Click += new EventHandler(this.btn_TianJia_Click);
            this.groupBox1.Controls.Add(this.dataGridView1);
            this.groupBox1.Location = new Point(2, 3);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new Size(0x1c4, 0x180);
            this.groupBox1.TabIndex = 0;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "装饰风格管理";
            this.dataGridView1.AllowUserToAddRows = false;
            this.dataGridView1.BackgroundColor = SystemColors.ControlLightLight;
            this.dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.dataGridView1.Columns.AddRange(new DataGridViewColumn[] { this.Column1, this.Column2 });
            this.dataGridView1.Location = new Point(4, 0x16);
            this.dataGridView1.Name = "dataGridView1";
            this.dataGridView1.ReadOnly = true;
            this.dataGridView1.RowHeadersWidth = 30;
            this.dataGridView1.RowTemplate.Height = 0x17;
            this.dataGridView1.Size = new Size(0x1ba, 0x161);
            this.dataGridView1.TabIndex = 0;
            this.dataGridView1.CellClick += new DataGridViewCellEventHandler(this.dataGridView1_CellClick_1);
            this.Column1.HeaderText = "编号";
            this.Column1.Name = "Column1";
            this.Column1.ReadOnly = true;
            this.Column1.Visible = false;
            this.Column2.HeaderText = "风格名称";
            this.Column2.Name = "Column2";
            this.Column2.ReadOnly = true;
            this.Column2.Width = 410;
            base.AutoScaleDimensions = new SizeF(6f, 12f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.ClientSize = new Size(0x1c5, 0x1d5);
            base.Controls.Add(this.panel1);
            base.FormBorderStyle = FormBorderStyle.FixedSingle;
            base.MaximizeBox = false;
            this.MaximumSize = new Size(0x1cb, 0x1f5);
            this.MinimumSize = new Size(0x1cb, 0x1f5);
            base.Name = "DesStyleInfo";
            this.Text = "装饰风格管理";
            this.panel1.ResumeLayout(false);
            this.groupBox3.ResumeLayout(false);
            this.groupBox3.PerformLayout();
            this.groupBox2.ResumeLayout(false);
            this.groupBox1.ResumeLayout(false);
            ((ISupportInitialize) this.dataGridView1).EndInit();
            base.ResumeLayout(false);
        }
    }
}

